package test;

import static org.junit.Assert.assertEquals;

import java.util.Iterator;
import java.util.List;

import movgen.Move2;
import movgen.Util;

import org.junit.Test;

import search.SEE;
import state.GameState;

public class SEETest2 {

	
	@Test public void evaluate() {     //take an undefended pawn, should be +100
		int side=0;
		int victim=GameState.BP;
		
		int[][] attackers = {  {GameState.WP}, {}  };
		int[] ptr = new int[2];
		ptr[GameState.WHITE] = 0;
		ptr[GameState.BLACK] = -1;
		
		int result = SEE.evaluate2(side, victim, attackers, ptr);
		System.out.println("Result=" + result);
		assertEquals(100, result);
		
	}
	
	@Test public void evaluateA() {    //exchange pawns, should be +1
		int side=0;
		int victim=GameState.BP;
		
		int[][] attackers = {  {GameState.WP}, {GameState.BP }  };
		int[] ptr = new int[2];
		ptr[GameState.WHITE] = 0;
		ptr[GameState.BLACK] = 0;
		
		int result = SEE.evaluate2(side, victim, attackers, ptr);
		System.out.println("Result=" + result);
		assertEquals(1, result);
		
	}
	@Test public void evaluateB() {    // pawn takes knight defended by pawn, should be +225
		int side=0;
		int victim=GameState.BN;
		
		int[][] attackers = {  {GameState.WP}, {GameState.BP }  };
		int[] ptr = new int[2];
		ptr[GameState.WHITE] = 0;
		ptr[GameState.BLACK] = 0;
		
		int result = SEE.evaluate2(side, victim, attackers, ptr);
		System.out.println("Result=" + result);
		assertEquals(225, result);
		
	}
	@Test public void evaluateC() {    // queen takes knight defended by pawn, should be -650, which is 0
		int side=0;
		int victim=GameState.BN;
		
		int[][] attackers = {  {GameState.WQ}, {GameState.BP }  };
		int[] ptr = new int[2];
		ptr[GameState.WHITE] = 0;
		ptr[GameState.BLACK] = 0;
		
		int result = SEE.evaluate2(side, victim, attackers, ptr);
		System.out.println("Result=" + result);
		assertEquals(0, result);
		
	}
	@Test public void evaluateD() {    // Rxr,  pxR, Rxp  = +100
		int side=0;
		int victim=GameState.BR;
		
		int[][] attackers = {  {GameState.WR, GameState.WR}, {GameState.BP }  };
		int[] ptr = new int[2];
		ptr[GameState.WHITE] = 1;
		ptr[GameState.BLACK] = 0;
		
		int result = SEE.evaluate2(side, victim, attackers, ptr);
		System.out.println("Result=" + result);
		assertEquals(100, result);
		
	}
	@Test public void evaluateE() {    // Rxr,  rxR, Rxr  =  500 ; white is a rook up
		int side=0;
		int victim=GameState.BR;
		
		int[][] attackers = {  {GameState.WR, GameState.WR}, {GameState.BR }  };
		int[] ptr = new int[2];
		ptr[GameState.WHITE] = 1;
		ptr[GameState.BLACK] = 0;
		
		int result = SEE.evaluate2(side, victim, attackers, ptr);
		System.out.println("Result=" + result);
		assertEquals(500, result);
		
	}
	@Test public void evaluateF() {    // Rxr,  rxR, Rxr, pxR ; even trade = 1
		int side=0;
		int victim=GameState.BR;
		
		int[][] attackers = {  {GameState.WR, GameState.WR}, {GameState.BP, GameState.BR  }  };
		int[] ptr = new int[2];
		ptr[GameState.WHITE] = 1;
		ptr[GameState.BLACK] = 1;
		
		int result = SEE.evaluate2(side, victim, attackers, ptr);
		System.out.println("Result=" + result);
		assertEquals(1, result);
		
	}
	@Test public void evaluateG() {    // Rxr,  pxR, Rxp, rxR ;   down -400 so = 0
		int side=0;
		int victim=GameState.BR;
		
		int[][] attackers = {  {GameState.WR, GameState.WR}, {GameState.BR, GameState.BP  }  };
		int[] ptr = new int[2];
		ptr[GameState.WHITE] = 1;
		ptr[GameState.BLACK] = 1;
		
		int result = SEE.evaluate2(side, victim, attackers, ptr);
		System.out.println("Result=" + result);
		assertEquals(0, result);
		
	}
	@Test public void evaluateH() {    // rxN, RxR so should be 0
		int side=1;
		int victim=GameState.WN;
		
		int[][] attackers = {  {GameState.WQ, GameState.WR}, {GameState.BR }  };
		int[] ptr = new int[2];
		ptr[GameState.WHITE] = 1;
		ptr[GameState.BLACK] = 0;
		
		int result = SEE.evaluate2(side, victim, attackers, ptr);
		System.out.println("Result=" + result);
		assertEquals(0, result);
		
	}
	@Test public void evaluateJ() {    // rxN, RxR, rxR, 
		int side=1;
		int victim=GameState.WN;
		
		int[][] attackers = {  { GameState.WR}, {GameState.BR, GameState.BR }  };
		int[] ptr = new int[2];
		ptr[GameState.WHITE] = 0;
		ptr[GameState.BLACK] = 1;
		
		int result = SEE.evaluate2(side, victim, attackers, ptr);
		System.out.println("Result=" + result);
		assertEquals(325, result);
		
	}
	@Test public void evaluateK() {    // rxN, Rxr, rxR, Rxr, pxR}
		int side=1;
		int victim=GameState.WN;
		
		int[][] attackers = {  { GameState.WR, GameState.WR}, {GameState.BP, GameState.BR, GameState.BR }  };
		int[] ptr = new int[2];
		ptr[GameState.WHITE] = 1;
		ptr[GameState.BLACK] = 2;
		
		int result = SEE.evaluate2(side, victim, attackers, ptr);
		System.out.println("Result=" + result);
		assertEquals(325, result);
		
	}
	@Test public void evaluateI() {    // pawn trade should be 1
		int side=1;
		int victim=GameState.WP;
		
		int[][] attackers = {  {GameState.WP}, {GameState.BP }  };
		int[] ptr = new int[2];
		ptr[GameState.WHITE] = 0;
		ptr[GameState.BLACK] = 0;
		
		int result = SEE.evaluate2(side, victim, attackers, ptr);
		System.out.println("Result=" + result);
		assertEquals(1, result);
		
	}
}
